package com.guldan.jaina.provider;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.guldan.core.dubbo.client.ResponseDTO;
import com.guldan.core.search.Pagination;
import com.guldan.jaina.dto.dicType.DicTypeDTO;
import com.guldan.jaina.dto.dicType.DicTypeSearchDTO;
import com.guldan.jaina.dto.dictionary.DictionaryDTO;
import com.guldan.jaina.dto.dictionary.DictionarySearchDTO;
import com.guldan.jaina.manager.DicTypeManager;
import com.guldan.jaina.manager.DictionaryManager;

/**
 * Created by Silas.
 * Date: 2016/11/7
 * Time: 22:54
 */
@Component
public class DictionaryProviderImpl implements IDictionaryProvider {

    @Autowired
    private DictionaryManager dictionaryManager;

    @Override
    public ResponseDTO<DictionaryDTO> get(Integer dictionaryId) {
        ResponseDTO<DictionaryDTO> response = new ResponseDTO<>();
        response.setData(dictionaryManager.get(dictionaryId));
        return response;
    }

    @Override
    public ResponseDTO<DictionaryDTO> save(DictionaryDTO dto) {
        ResponseDTO<DictionaryDTO> response = new ResponseDTO<>();
        try {
            response.setData(dictionaryManager.save(dto));
        } catch (Exception ex) {
            response.setStatus(false);
            response.setException(ex);
        }
        return response;
    }

    @Override
    public ResponseDTO<Boolean> delete(Integer dictionaryId) {
        ResponseDTO<Boolean> response = new ResponseDTO<>();
        response.setData(dictionaryManager.delete(dictionaryId));
        return response;
    }

    @Override
    public ResponseDTO<Pagination<DictionaryDTO>> list(DictionarySearchDTO dictionarySearchDTO) {
        ResponseDTO<Pagination<DictionaryDTO>> response = new ResponseDTO<>();
        response.setData(dictionaryManager.list(dictionarySearchDTO));
        return response;
    }

	@Override
	public ResponseDTO<List<DictionaryDTO>> all(DictionarySearchDTO dictionarySearchDTO) {
        ResponseDTO<List<DictionaryDTO>> response = new ResponseDTO<>();
        response.setData(dictionaryManager.all(dictionarySearchDTO));
        return response;
	}

}
